home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2765 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: news.ov.com!news
  2. From: glenn@ov.com (Fletcher.Glenn@ov.com)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Question on pointer-to-pointer-to-pointer
  5. Date: 23 Jan 1996 21:48:21 GMT
  6. Organization: OpenVision
  7. Message-ID: <4e3l35$j22@spanky.pls.ov.com>
  8. References: <4dq2ej$m3t@cssun.cs.usm.my>
  9. Reply-To: glenn@ov.com
  10. NNTP-Posting-Host: foghorn.pls.ov.com
  11.  
  12. In article m3t@cssun.cs.usm.my, bahari@cs.usm.my (Bahari Belaton (Dr)) writes:
  13. >Hi,
  14. >Below is one of the question asked by my student about pointer-to-pointer in
  15. >C - with a specific example on strtod() function. Can anyone help me explain
  16. >this to my student. Especially on the important of pointer-to-pointer.
  17. >
  18. >Thanks
  19. >
  20. >Bahari Belaton
  21. >
  22. >=======================================================================
  23. >Dear All,
  24. >     I hope you can enlighthen me a bit.
  25. >Query 1:
  26. >     According to Deitel, the function prototype for strtod() is:-
  27. >     double strtod(const char *nPtr, char **endPtr) and the function call is
  28. >as follows :-
  29. >     double d;
  30. >     char *string = "51.2% are admitted";
  31. >     char *stringPtr;
  32. >
  33. >     d = strtod(string, &stringPtr);
  34. >
  35. >The book says that &stringPtr is assigned the location of the first character
  36. >after the converted value. How does the function do that?
  37.  
  38. Remember, a function cannot modify an argument unless the argument is a pointer
  39. to the object to be modified.  Thus if you want the strtod() function to 
  40. set a pointer to the next character, you must supply a pointer to the
  41. memory location to contain the result (a char *).  Of course &(char *) is
  42. a char **.
  43.  
  44. >
  45. >I'm still confused with **endPtr. Why the **endPtr(pointer to a
  46. >pointer) is used?(What is the significance of using a double pointer? Why
  47. >not just *endPtr since the function assigned the address of first
  48. >character of the string to &stringPtr. (what about***endPtr?
  49. >How many pointers to pointer can we used?)
  50.  
  51. The number of levels of indirection is usually limited by human understanding
  52. before it is limited by the compiler.  Most programs do not use more than
  53. 3 levels of indirection.
  54.  
  55. >
  56. >Thank you very much.
  57. >Your student,
  58. >LEE KENG TUNG csi36864@wira2.cs.usm.my
  59. >
  60. >=================================
  61.  
  62.  
  63.         Fletcher.Glenn@ov.com
  64.  
  65.